﻿<?php
	include '../inc/conn.php';
	include '../sendmail.php';
	session_start();
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	
	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}

	if (isset($act))
	{
		if (empty($vContent) || empty($iStatus)){
			echo "<script>alert('Some content must be filled in data!!');</script>";
			die("Some content must be filled in data!");
		}

		if ($act == 'mod')
		{
		if (empty($vContent) || empty($iStatus)){
			echo "<script>alert('Some content must be filled in data!!');</script>";
			die("Some content must be filled in data!");
		}
		if ($act == 'mod')
		{	
			date_default_timezone_set('Asia/Shanghai');
			$db = new mysql();
			$table = "mail_tracking";
			$condition = "id=".$id;
			$mod_content="content=\"".htmlentities($vContent,ENT_QUOTES)."\", 
			status='".htmlentities($iStatus,ENT_QUOTES)."', sendto='${sendto}'";
			
			$db->update($table, $mod_content, $condition);
			//SendMail($title, $vContent, $sendto);
			$param = array(
				'aSync'=>'Yes',
				'title'=>$title,
				'msg'=>$vContent,
				'to'=>$sendto
			);
			doAsyncMail($param);
			echo "<script>alert('Data changed!');window.opener.location.reload();window.close();</script>";
			$db->close();

		}
		}
	}
	
	if (!isset($id))
	{
		echo "<script>alert('ID is empty!');</script>";
		die("ID is empty!");
	}
	
	$db = new mysql();
	$sql = "select * from mail_tracking where id=".$id;
	$db->query($sql);
	$num = $db->db_num_rows();
	if ($num == 0)
		die("No data was found!");
	$row = $db->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
<title>更新邮件追踪内容</title>
</head>
<body class="background">
<div class="container white-background pagecontent">
<form action="mod_mail.php?id=<? echo $id; ?>&act=mod" method="post">
<div>
<div class="input-group">
		<span class="input-group-addon">标题:</span>
		<input name="title" type="text" class="form-control" value="<? echo $row['title'] ?>">
	</div>
追踪内容:<br />
<textarea name="vContent" rows="12" cols="80" class="xheditor {tools:'mfull',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:740px;height:280px;">
<?
	echo htmlspecialchars_decode($row['content']);
?>
</textarea>
</div>
<div>
状态:<select name="iStatus" id="iStatus">
<? 
	if ($row['status'] == "Open") 
		echo '<option value="Open" selected="selected">Open</option>';
	else
		echo '<option value="Open">Open</option>';
		
	if ($row['status'] == "Tracking") 
		echo '<option value="Tracking" selected="selected">Tracking</option>';
	else
		echo '<option value="Tracking">Tracking</option>';
	
	if ($row['status'] == "Close") 
		echo '<option value="Close" selected="selected">Close</option>';
	else
		echo '<option value="Close">Close</option>';	
?>
</select>
发送到:<select name="sendto" id="idept">
<?
	if ($row['sendto'] == "TE")
		echo '<option value="TE" selected="selected">TE</option>';
	else
		echo '<option value="TE">TE</option>';
		
	if ($row['sendto'] == "SW")
		echo '<option value="SW" selected="selected">SW</option>';
	else
		echo '<option value="SW">SW</option>';
	
	if ($row['sendto'] == "PT")
		echo '<option value="PT" selected="selected">PT</option>';
	else
		echo '<option value="PT">PT</option>';
?>
</select>
</div>

<div><input class="btn btn-success btn-primary" name="submit" value="提交" type="submit"><input class="btn btn-danger" name="reset" value="重填" type="reset"></div>
</form>
</div>
</body>
</html>
